package com.dqyz.busi.service.impl;

import java.util.List;

import com.dqyz.busi.domain.vo.CompetitionVo;
import com.dqyz.common.exception.ServiceException;
import com.dqyz.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dqyz.busi.mapper.CompetitionMapper;
import com.dqyz.busi.domain.Competition;
import com.dqyz.busi.service.ICompetitionService;

/**
 * 赛事管理Service业务层处理
 * 
 * @author wangguan
 * @date 2024-09-27
 */
@Service
public class CompetitionServiceImpl implements ICompetitionService 
{
    @Autowired
    private CompetitionMapper competitionMapper;

    /**
     * 查询赛事管理
     * 
     * @param id 赛事管理主键
     * @return 赛事管理
     */
    @Override
    public Competition selectCompetitionById(Long id)
    {
        return competitionMapper.selectCompetitionById(id);
    }

    /**
     * 查询赛事管理列表
     * 
     * @param competition 赛事管理
     * @return 赛事管理
     */
    @Override
    public List<Competition> selectCompetitionList(Competition competition)
    {
        return competitionMapper.selectCompetitionList(competition);
    }

    /**
     * 查询赛事管理列表
     *
     * @param competition 赛事管理
     * @return 赛事管理Vo
     */
    @Override
    public List<CompetitionVo> selectCompetitionVoList(Competition competition)
    {
        return competitionMapper.selectCompetitionVoList(competition);
    }

    /**
     * 新增赛事管理
     * 
     * @param competition 赛事管理
     * @return 结果
     */
    @Override
    public int insertCompetition(Competition competition)
    {
        competition.setCreateTime(DateUtils.getNowDate());
        return competitionMapper.insertCompetition(competition);
    }

    /**
     * 修改赛事管理
     * 
     * @param competition 赛事管理
     * @return 结果
     */
    @Override
    public int updateCompetition(Competition competition)
    {
        competition.setUpdateTime(DateUtils.getNowDate());
        return competitionMapper.updateCompetition(competition);
    }

    /**
     * 批量删除赛事管理
     * 
     * @param ids 需要删除的赛事管理主键
     * @return 结果
     */
    @Override
    public int deleteCompetitionByIds(Long[] ids)
    {
        return competitionMapper.deleteCompetitionByIds(ids);
    }

    /**
     * 删除赛事管理信息
     * 
     * @param id 赛事管理主键
     * @return 结果
     */
    @Override
    public int deleteCompetitionById(Long id)
    {
        return competitionMapper.deleteCompetitionById(id);
    }

    @Override
    public Competition publishCompetitionById(Long id) {
        Competition competition = competitionMapper.selectCompetitionById(id);
        if(competition.getRaceSchemaId() == null) {
            throw new ServiceException("请先关联赛事方案");
        }
        competition.setUpdateTime(DateUtils.getNowDate());
        competition.setIsPublished(1L);
        competitionMapper.updateCompetition(competition);
        return competition;
    }
}
